<?php
/**
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/4/13
 * Time: 13:33
 */
class GethishulijilujsonController extends Yaf_Controller_Abstract
{

    function IndexAction()
    {
        $request = $this->getRequest();
        $type = $request->getPost('type','');
        $zhuyuan_id = $request->getPost('zhuyuan_id','');
        $yiyuan_id = $request->getPost('yiyuan_id','');
        if($yiyuan_id === "" )
        {
            Utility::apiJsonError(20028, '请输入医院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }


        if($zhuyuan_id === "" )
        {
            Utility::apiJsonError(20050, '请输入住院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
            Utility::apiJsonError(20055, '住院ID必须是整型');
        }

        if($type == "")
        {
            Utility::apiJsonError(20058, '请输入住院查询类型');
        }
        $hisziduan = Yaconf::get("config$yiyuan_id.hishulijilu_ziduan");
        if($hisziduan == "")
        {
            $hisziduan = "valcol14,valcol16,valcol18,valcol20,valcol22,valcol24,valcol26";
        }
        $his_result = DB::select($hisziduan)
            ->from("zhuyuan_huli_wenshu_detail_his")
            ->where("zhuyuan_id","=",$zhuyuan_id)
            ->and_where("type","=",$type)
            ->and_where("yiyuan_id","=",$yiyuan_id)
            ->order_by("jilu_time","DESC")
            ->execute()
            ->offsetGet(0);
        $async_result["result"]= $his_result;
        if(is_array($async_result)&&count($async_result)>0)
        {
            $async_result["state"] = "1";
        }else{
            $async_result["state"] = "0";
        }
        $async_result["status_info"] = "数据同步成功:)";
        $async_result["error"] = 200;
        $async_result["msg"] = "";
        Utility::apiJsonResultExtends($async_result);

    }
}